package com.cj.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
public class MyTestController {
    private static ArrayList<String> list = new ArrayList<>();

    @GetMapping("/testAjax1")
    public String doAjax1(){
        return "返回的AJAX";
    }
    @GetMapping("/selectOne")
    public String doSelectOne(String name){
        if(list.contains(name))
            return "用户名重复";
        else
            return "可以注册";
    }


    @PostMapping("doSave")
    public String doSave(String name){
        String value = this.doSelectOne(name);
        if("用户名重复".equals(value))
            return value;
        else
            list.add(name);
            return "注册成功啦";
    }
}
